# Contributor: Valery Kartel <valery.kartel@gmail.com>
# Contributor: Łukasz Jendrysik <scadu@yandex.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=btrfs-progs
pkgver=6.11
pkgrel=1
pkgdesc="BTRFS filesystem utilities"
url="https://btrfs.wiki.kernel.org"
arch="all"
license="GPL-2.0-or-later"
depends_dev="linux-headers"
makedepends="$depends_dev
	acl-dev
	asciidoc
	attr-dev
	e2fsprogs-dev
	eudev-dev
	lzo-dev
	py3-setuptools
	py3-sphinx
	python3-dev
	util-linux-dev
	xmlto
	zlib-dev
	zstd-dev
	"
checkdepends="
	acl
	coreutils
	libaio-dev
	liburing-dev
	losetup
	xz
	"
subpackages="
	$pkgname-doc
	$pkgname-static
	$pkgname-dev
	$pkgname-bash-completion
	py3-$pkgname:py3
	$pkgname-libs
	$pkgname-extra
	$pkgname-openrc
	"
source="https://www.kernel.org/pub/linux/kernel/people/kdave/btrfs-progs/btrfs-progs-v$pkgver.tar.xz
	btrfs-scan.initd
	remove-sphinx_rtd_theme.patch
	basename.patch
	"
builddir="$srcdir/$pkgname-v$pkgver"
# most pass, one fails to build (fsstress renameat2)
options="!check"

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--disable-backtrace
	make
}

check() {
	make test
}

package() {
	make DESTDIR="$pkgdir" install install_python

	mkdir -p "$pkgdir"/usr/share/doc/$pkgname
	install -m644 README.md CHANGES \
		"$pkgdir"/usr/share/doc/$pkgname

	mkdir "$pkgdir"/sbin
	local i; for i in btrfs btrfsck fsck.btrfs mkfs.btrfs; do
		mv "$pkgdir"/usr/bin/$i "$pkgdir"/sbin/
	done
	mv "$pkgdir"/usr/bin "$pkgdir"/usr/sbin

	install -Dm644 btrfs-completion \
		"$pkgdir"/usr/share/bash-completion/completions/btrfs

	install -Dm755 "$srcdir"/btrfs-scan.initd "$pkgdir"/etc/init.d/btrfs-scan
}

py3() {
	pkgdesc="Python 3 bindings for $pkgname"
	provides="py-btrfs-progs=$pkgver-r$pkgrel"  # for backward compatibility
	replaces="py-btrfs-progs"  # for backward compatibility

	amove usr/lib/python*
}

extra() {
	depends="$pkgname"
	pkgdesc="BTRFS filesystem extra utilities"

	amove usr/sbin
}

sha512sums="
fad3c7e908e2020a3983f9737a7e87367023e2ad35aea14197e2bfa71c1e0435bc3da3f7e6ef463de47c033323163f8b1b7933013042c6fcea673d0f4723ade1  btrfs-progs-v6.11.tar.xz
8f8757e094e5cb3b2748e2b41ba3c50d4535e24c5ced3b31eea6457f61f9fe90894a51d512d306ec8ea20ace6bb8dfe00422d3cbea9734568b492a044d4b2018  btrfs-scan.initd
c8354118cc4f17d19213a99580c2d8c0cf3173a91c5e42a62c8a7d3b2b66395419136b9761d70503ced0fc959cf8071ae2e2dc1667f000bf0ac86eddc9253bb3  remove-sphinx_rtd_theme.patch
8f88c06bd244f41cb318b5f432edcf8d7db06dfdb886e75f1b33f6e911a772f32b3b5d67181967469706cf29a37acbe4bc9ec63f6f16a6450b061f17ae1d2fa8  basename.patch
"
